home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / js.zip / CALENDAR.JS < prev    next >
Text File  |  1992-12-30  |  2KB  |  87 lines

  1.    NB.  This file can be used as a script input file to J Version 6.1
  2.    NB.  December 1992
  3.    
  4.    NB.  Donald B. McIntyre
  5.    NB.  Luachmhor, 1 Church Road
  6.    NB.  KINFAUNS, PERTH PH2 7LD
  7.    NB.  SCOTLAND - U.K.
  8.    NB.  Telephone:  In the UK:      0738-86-726
  9.    NB.  From USA and Canada:   011-1-738-86-726
  10.    NB.  email:  donald.mcintyre@almac.co.uk
  11.  
  12. NB. Keith W. Smillie's J Version of E.E.McDonnell's Calendar algorithm
  13. NB. As revised by E.E. McDonnell.  Copyright Iverson Software Inc.
  14. NB. Some additional notes by Donald B. McIntyre
  15.  
  16. NB. Keith Smillie has since published the following article:
  17. NB. "Making a Calendar in J", VECTOR Vol. 9#1 (July 1992) 85-91
  18. NB. (I have not compared the VECTOR version with this one.  DBM)
  19.  
  20. NB. Utilities
  21. pi=. >:@i.
  22. div=. <.@%& 4 100 400
  23. mod=. 4 100 400 & |
  24. dayno=. 7&|
  25.  
  26. NB. Constants
  27. DAYS=. ' Su Mo Tu We Th Fr Sa'
  28. MONTHS=. 'JanFebMarAprMayJunJulAugSepOctNovDec'
  29. LENGTHS=. 31 28 31 30 31 30 31 31 30 31 30 31
  30.  
  31. NB. Month name centered.
  32. mn=. _12&{.@]@{&(_3]\MONTHS)
  33.  
  34. NB. Leap year test
  35. ly=. 0&(~:/ .=)@mod
  36.  
  37. NB. Month lengths adjusted for leap year
  38. LENGTHSadj=. LENGTHS&+@((LENGTHS=28)&(*. ly))
  39.  
  40. NB. Month length
  41. ml=. {LENGTHSadj
  42.  
  43. NB. New Year's date
  44. nydate=. >:@(365&*+-/@div)@(]@-&1601)
  45.  
  46. NB. Ordinal date
  47. odate=. +/@({.LENGTHSadj)
  48.  
  49. NB. First day of month
  50. mb=. -@dayno@(odate+nydate@])
  51.  
  52. NB. Month calendar without headings
  53. mctable=. ,"_1@(6 7&$)@(mb |. (42&{.)@(3&":)@,.@pi@ml)
  54.  
  55. NB. Month calendar
  56. mc=. (mn@[),(DAYS&,@mctable)
  57.  
  58. NB. Calendar for given number of months
  59. cal=. (i.@[)mc"0]
  60.  
  61. NB. Calendar with 4 rows and 3 columns
  62. calendar=. <"2@(4 3&cal)
  63.  
  64. NB.  calendar 1992
  65. NB.  calendar"0 ]1991 1992 1993
  66. NB. These took 3.96 and 11.76 seconds respectively on PS/2#70
  67.  
  68. NB. Keith W. Smillie's version is so slow you may think you
  69. NB. are in an endless loop!
  70. NB. calendar 1992                  Took  52.6 seconds on PS/2#70
  71. NB. calendar"0 ]1991 1992 1993     Took 157.6 seconds on PS/2#70
  72.  
  73. NB.  The following illustrate how we can isolate individual verbs
  74. NB.  for testing and study
  75. NB.      1 2 cal 1992
  76. NB.      1 2 mc"0 ]1992
  77. NB.      1 2 mctable"0 ]1992
  78. NB.      mn 1 2
  79. NB.      1 2 mb"0 ]1992
  80. NB.      1 2 odate"0 ]1992
  81. NB.      2 odate 1992
  82. NB.      2 ({.LENGTHSadj) 1992
  83. NB.      2 {. (LENGTHSadj 1992)
  84. NB.      2 ml 1992
  85. NB.      2 ({LENGTHSadj) 1992
  86. NB.      2 { (LENGTHSadj 1992)
  87.